"""
PyMySQL访问数据库 - 删除数据
"""
import pymysql

import common

no = int(input('请输入要删除的学生学号: '))
conn = common.get_conn(database='school')
try:
    with conn.cursor() as cursor:
        result = cursor.execute(
            'delete from tb_student where stuid=%s', no
        )
        print('删除成功!!!' if result == 1 else '没有该学生!!!')
    conn.commit()
except pymysql.MySQLError as err:
    conn.rollback()
    print(err, '删除失败!!!')
finally:
    conn.close()